import "./index.scss";
import { useNavigate, useLocation } from "react-router-dom";

const ArticleDetails = () => {
  //取数据
  const state = useLocation();
  console.log("state", state.state);

  //返回上一个页面
  const navigate = useNavigate();
  const back = () => {
    navigate("/zhome/z-policyArticles");
  };
  //时间转换
  const toDub = (n: any) => (n < 10 ? "0" + n : "" + n);
  //年月日时分秒
  const toTime = (date: any) => {
    const oTime = new Date(date);
    return (
      oTime.getFullYear() +
      "-" +
      toDub(oTime.getMonth() + 1) +
      "-" +
      toDub(oTime.getDate()) +
      " " +
      toDub(oTime.getHours()) +
      ":" +
      toDub(oTime.getMinutes()) +
      ":" +
      toDub(oTime.getSeconds())
    );
  };
  //年月日
  const toDate = (date: any) => {
    const oTime = new Date(date);
    return (
      oTime.getFullYear() +
      "年" +
      toDub(oTime.getMonth() + 1) +
      "月" +
      toDub(oTime.getDate()) +
      "日"
    );
  };

  return (
    <div className="articleDetails">
      <div className="top">
        <div className="top-l">
          <div className="title" onClick={back}>
            政策通告文章
          </div>
          <div>&gt;</div>
          <div className="detail">详情</div>
        </div>
      </div>

      <div className="hr"></div>

      <div className="titName">
        <p>{state.state.atitle}</p>
        <div className="smallName">
          <p>{toTime(state.state.atime)}</p>
        </div>
      </div>

      <div className="content">
        <p>{state.state.acontent}</p>
        <div className="conButton">
          <p>成都市教育局</p>
          <p style={{ paddingBottom: "20px" }}>{toDate(state.state.atime)}</p>
        </div>
      </div>
    </div>
  );
};
export default ArticleDetails;
